package main.Q2101_2200;

public class Q2101_2110 {
	public static void main(String[] args) {
		System.out.println("Question2101：");
		System.out.println("Question2102：");
		System.out.println("Question2103：");
		System.out.println("Question2104：");
		System.out.println("Question2105：给植物浇水Ⅱ");
		System.out.println("Question2106：");
		System.out.println("Question2107：");
		System.out.println("Question2108：");
		System.out.println("Question2109：");
		System.out.println("Question2110：");
	}
}

class Question2105{
	public int minimumRefill(int[] plants, int capacityA, int capacityB) {
		int count=0;
		int left=0,right=plants.length-1,curA=capacityA,curB=capacityB;
		while (left<=right) {
			if (left==right) {//浇同一株植物
				int temp= curA>=curB ? curA : curB;//剩水多者浇
				if (temp<plants[left]) count++;//灌水
			}else {//浇不同株植物
				curA-=plants[left];//浇水
				curB-=plants[right];
				if (right-left>2) {
					if (curA<plants[left+1]) {
						curA=capacityA;
						count++;
					}
					if (curB<plants[right-1]) {
						curB=capacityB;
						count++;
					}
				}else if (right-left==2){
					if (curA>=curB) {
						if (curA<plants[left+1]) {
							curA=capacityA;
							count++;
						}
					}else {
						if (curB<plants[right-1]) {
							curB=capacityB;
							count++;
						}
					}
				}
			}
			left++;
			right--;
		}
		return count;
	}
}